
import Vue from 'vue'
import Vuex from 'vuex'
import Axios from "axios"
Vue.use(Vuex)

export default new Vuex.Store({
  //变量名 不要和 组件里面相同
  state: {

    // 所有店铺类型
    AllShopTypes: {},
    // 美食店铺类型
    DeliciousFoodShopTypes: [],
    // 购物店铺类型
    ShoppingStoreTypes: [],
    // 美食店铺数据
    DeliciousFoodShopDatas: [],
    // 购物店铺数据
    ShoppingStoreDatas: [],
    // 某个店铺数据
    thatStoreData: {},
    // 楼层编号
    FloorNumbering: [],
    // 地图所有数据
    MapAllData: [],
    // 某个车数据
    thatCarData: [],
    //数据页面存放的商铺数据列表
    DataPageList:[],
    //App页获取的地图数据
    AppMapAllData:[]
  },
  mutations: {

    // 所有店铺类型
    fun_AllShopTypes(state, item) { 
      state.AllShopTypes = item
    },
    // 美食店铺类型
    fun_DeliciousFoodShopTypes(state, item) {
      state.DeliciousFoodShopTypes = item
    },
    // 购物店铺类型
    fun_ShoppingStoreTypes(state, item) {
      state.ShoppingStoreTypes = item
    },
    // 美食店铺数据
    fun_DeliciousFoodShopDatas(state, item) {
      state.DeliciousFoodShopDatas = item
    },
    // 购物店铺数据
    fun_ShoppingStoreDatas(state, item) {
      state.ShoppingStoreDatas = item
    },
    // // 某个店铺数据

    fun_thatStoreData(state, item) {
      state.thatStoreData = item
    },
    // // 楼层编号
    fun_FloorNumbering(state, item) {
      state.FloorNumbering = item
    },
    // // 地图所有数据
    // fun_MapAllData(state, item) {
    //   state.MapAllData = item
    // },
    fun_DataPageList(state, item) { 
      state.DataPageList = item
    },
    //App页获取的地图数据 地图所有数据
    fun_AppMapAllData(state, item) {
      state.AppMapAllData = item
    },
    // // 某个车数据
    // fun_thatCarData(state, item) {
    //   state.thatCarData = item
    // },
  },
  actions: {
    //获取 所有店铺类型
    actions_getAllType(context) {
      Axios.get('https://map.ckiosk.cn/webAPI/ClientService.asmx/Command?code={%22pid%22:%22261FDAD7-33F9-40A4-BD33-25F1C884F54C%22,%22lan%22:%22SC%22,%22command%22:%22GetMallBrandType%22,%22parameter%22:{%22KEY%22:%22BAF3CB32-E8F2-40A6-AE1A-A5BFE2CB6E14%22}}', {
          headers: {
            'content-type': 'application/x-www-form-urlencoded'
          },
        })
        .then(res => {
          //获取 所有大的类型
          context.commit('fun_AllShopTypes', res.data.v)
          let tempAll = res.data.v;
          let tempFood = [];
          let tempShopping = [];
          for (let index = 0; index < tempAll.length; index++) {
            const element = tempAll[index];
            // console.log('element :', element);
            //美食 类别
            if (element.ShopTypeParenID == "EFBD909F-7685-4D84-9A3C-A7C45A9C5ACC") {
              tempFood.push(element)
            }
            if (element.ShopTypeParenID == "E5BBBE48-75D4-41A6-B832-512CFC3630B6") {
              tempShopping.push(element)
            }
          }
          // console.log('tempAll :', tempAll);
          // console.log('tempFood :', tempFood);
          // console.log('tempShopping :', tempShopping);

          // 将类型储存
          context.commit('fun_DeliciousFoodShopTypes', tempFood)
          context.commit('fun_ShoppingStoreTypes', tempShopping)
        })
    },
  }
})
